﻿using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.IO.Ports;
using System.Media;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;

namespace avrdudeGUI
{
	// Token: 0x02000006 RID: 6
	public partial class MainForm : Form
	{
		// Token: 0x06000011 RID: 17 RVA: 0x00004334 File Offset: 0x00003334
		private void AvrdudeButton_Click(object sender, EventArgs e)
		{
			this.OpenFileDialog.CheckFileExists = true;
			this.OpenFileDialog.Filter = "avrdude.exe|avrdude.exe";
			this.OpenFileDialog.FileName = "";
			this.OpenFileDialog.Title = "Select avrdude.exe File";
			this.OpenFileDialog.ShowDialog();
			if (this.OpenFileDialog.FileName.Length > 0)
			{
				this.AvrdudeTextBox.Text = this.OpenFileDialog.FileName;
				this.AvrdudeInfo();
			}
		}

		// Token: 0x06000012 RID: 18 RVA: 0x000043C8 File Offset: 0x000033C8
		private void ChipEraseButton_Click(object sender, EventArgs e)
		{
			if (MessageBox.Show("All the settings and data in the device are deleted. Is it good ?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
			{
				this.ExecCommand("-e", 50, false);
			}
		}

		// Token: 0x06000013 RID: 19 RVA: 0x0000440C File Offset: 0x0000340C
		private void TerminalButton_Click(object sender, EventArgs e)
		{
			if (this.AvrdudeTextBox.Text.Length == 0)
			{
				MessageBox.Show("Select avrdude.exe File", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.AvrdudeButton.Focus();
			}
			else if (this.ProgrammerComboBox.SelectedIndex < 0)
			{
				MessageBox.Show("Select Programmer", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.ProgrammerComboBox.Focus();
			}
			else if (this.DeviceComboBox.SelectedIndex < 0)
			{
				MessageBox.Show("Select Device", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.DeviceComboBox.Focus();
			}
			else
			{
				ProcessStartInfo processStartInfo = new ProcessStartInfo();
				processStartInfo.FileName = Environment.GetEnvironmentVariable("comspec");
				processStartInfo.Arguments = " /K \"" + this.AvrdudeTextBox.Text + "\" ";
				ProcessStartInfo processStartInfo2 = processStartInfo;
				processStartInfo2.Arguments += this.GetArg();
				ProcessStartInfo processStartInfo3 = processStartInfo;
				processStartInfo3.Arguments += " -t";
				Process process = Process.Start(processStartInfo);
				process.WaitForExit();
			}
		}

		// Token: 0x06000014 RID: 20 RVA: 0x00004544 File Offset: 0x00003544
		private void ReadFuseButton_Click(object sender, EventArgs e)
		{
			this.HFuseTextBox.Text = "";
			this.LFuseTextBox.Text = "";
			this.EFuseTextBox.Text = "";
			string text = "_hfuse_.txt";
			string text2 = "_lfuse_.txt";
			string str = "_efuse_.txt";
			string str2 = Environment.GetEnvironmentVariable("temp") + "\\";
			File.Delete(str2 + text);
			File.Delete(str2 + text2);
			File.Delete(str2 + str);
			if (this.ExecCommand(string.Concat(new string[]
			{
				"-U hfuse:r:",
				text,
				":h -U lfuse:r:",
				text2,
				":h"
			}), 150, false) == 0)
			{
				if (File.Exists(str2 + text))
				{
					StreamReader streamReader = new StreamReader(str2 + text);
					string text3 = streamReader.ReadLine();
					if (text3.Length == 3)
					{
						this.HFuseTextBox.Text = "0" + text3.Substring(2, 1).ToUpper();
					}
					else if (text3.Length == 4)
					{
						this.HFuseTextBox.Text = text3.Substring(2, 2).ToUpper();
					}
					streamReader.Close();
				}
				if (File.Exists(str2 + text2))
				{
					StreamReader streamReader = new StreamReader(str2 + text2);
					string text3 = streamReader.ReadLine();
					if (text3.Length == 3)
					{
						this.LFuseTextBox.Text = "0" + text3.Substring(2, 1).ToUpper();
					}
					else if (text3.Length == 4)
					{
						this.LFuseTextBox.Text = text3.Substring(2, 2).ToUpper();
					}
					streamReader.Close();
				}
				Cursor value = Cursor.Current;
				Cursor.Current = Cursors.WaitCursor;
				Thread.Sleep(500);
				Cursor.Current = value;
				if (this.ExecCommand("-U efuse:r:" + str + ":h", 50, true) == 0)
				{
					if (File.Exists(str2 + str))
					{
						StreamReader streamReader = new StreamReader(str2 + str);
						string text3 = streamReader.ReadLine();
						if (text3.Length == 3)
						{
							this.EFuseTextBox.Text = "0" + text3.Substring(2, 1).ToUpper();
						}
						else if (text3.Length == 4)
						{
							this.EFuseTextBox.Text = text3.Substring(2, 2).ToUpper();
						}
						streamReader.Close();
					}
				}
			}
			File.Delete(str2 + text);
			File.Delete(str2 + text2);
			File.Delete(str2 + str);
		}

		// Token: 0x06000015 RID: 21 RVA: 0x00004888 File Offset: 0x00003888
		private void WriteFuseButton_Click(object sender, EventArgs e)
		{
			Regex regex = new Regex("^[0-9A-Fa-f]{2}$");
			if (this.HFuseTextBox.Text.Length > 0 && !regex.Match(this.HFuseTextBox.Text).Success)
			{
				MessageBox.Show("Please Set hfuse by the hexadecimal number of 2 charactors. ", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.HFuseTextBox.Focus();
			}
			else if (this.LFuseTextBox.Text.Length > 0 && !regex.Match(this.LFuseTextBox.Text).Success)
			{
				MessageBox.Show("Please Set lfuse by the hexadecimal number of 2 charactors. ", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.LFuseTextBox.Focus();
			}
			else if (this.EFuseTextBox.Text.Length > 0 && !regex.Match(this.EFuseTextBox.Text).Success)
			{
				MessageBox.Show("Please Set efuse by the hexadecimal number of 2 charactors. ", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.EFuseTextBox.Focus();
			}
			else if (this.HFuseTextBox.Text.Length == 0 && this.LFuseTextBox.Text.Length == 0 && this.EFuseTextBox.Text.Length == 0)
			{
				MessageBox.Show("Please Set hfuse, lfuse or efuse.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
			}
			else if (MessageBox.Show("Fuses is ReWritten. Is it good ?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
			{
				int num = 50;
				string text = "";
				if (this.HFuseTextBox.Text.Length > 0)
				{
					text = text + "-U hfuse:w:0x" + this.HFuseTextBox.Text + ":m";
					num += 50;
				}
				if (this.LFuseTextBox.Text.Length > 0)
				{
					text = text + " -U lfuse:w:0x" + this.LFuseTextBox.Text + ":m";
					num += 50;
				}
				if (this.EFuseTextBox.Text.Length > 0)
				{
					text = text + " -U efuse:w:0x" + this.EFuseTextBox.Text + ":m";
					num += 50;
				}
				this.ExecCommand(text, num, false);
			}
		}

		// Token: 0x06000016 RID: 22 RVA: 0x00004AEC File Offset: 0x00003AEC
		private void ReadLockBitButton_Click(object sender, EventArgs e)
		{
			this.LockBitTextBox.Text = "";
			string str = Environment.GetEnvironmentVariable("temp") + "\\";
			string str2 = "_lockbit_.txt";
			File.Delete(str + str2);
			this.ExecCommand("-U lock:r:" + str2 + ":h", 100, false);
			if (File.Exists(str + str2))
			{
				StreamReader streamReader = new StreamReader(str + str2);
				string text = streamReader.ReadLine();
				if (text.Length == 3)
				{
					this.LockBitTextBox.Text = "0" + text.Substring(2, 1).ToUpper();
				}
				else if (text.Length == 4)
				{
					this.LockBitTextBox.Text = text.Substring(2, 2).ToUpper();
				}
				streamReader.Close();
				File.Delete(str + str2);
			}
		}

		// Token: 0x06000017 RID: 23 RVA: 0x00004BF8 File Offset: 0x00003BF8
		private void WriteLockBitButton_Click(object sender, EventArgs e)
		{
			Regex regex = new Regex("^[0-9A-Fa-f]{2}$");
			if (this.LockBitTextBox.Text.Length == 0)
			{
				MessageBox.Show("Please Set Lock bit.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
			}
			else if (!regex.Match(this.LockBitTextBox.Text).Success)
			{
				MessageBox.Show("Please Set Lock bit by the hexadecimal number of 2 charactors. ", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.LockBitTextBox.Focus();
			}
			else if (MessageBox.Show("Lock bit is ReWritten. Is it good ?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
			{
				this.ExecCommand("-U lock:w:0x" + this.LockBitTextBox.Text + ":m", 150, false);
			}
		}

		// Token: 0x06000018 RID: 24 RVA: 0x00004CCC File Offset: 0x00003CCC
		private void FlashFileButton_Click(object sender, EventArgs e)
		{
			this.OpenFileDialog.CheckFileExists = false;
			this.OpenFileDialog.AddExtension = true;
			this.OpenFileDialog.DefaultExt = "hex";
			this.OpenFileDialog.Filter = "Intel Hex File(*.hex)|*.hex|All File(*.*)|*.*";
			this.OpenFileDialog.FileName = "";
			this.OpenFileDialog.ShowDialog();
			if (this.OpenFileDialog.FileName.Length > 0)
			{
				this.FlashFileTextBox.Text = this.OpenFileDialog.FileName;
			}
		}

		// Token: 0x06000019 RID: 25 RVA: 0x00004D68 File Offset: 0x00003D68
		private void ReadFlashButton_Click(object sender, EventArgs e)
		{
			this.SaveFileDialog.AddExtension = true;
			this.SaveFileDialog.DefaultExt = "hex";
			this.SaveFileDialog.FileName = "";
			this.SaveFileDialog.Filter = "Hex File (*.hex)|*.hex|All File (*.*)|*.*";
			this.SaveFileDialog.OverwritePrompt = true;
			this.SaveFileDialog.Title = "Save Flash data";
			this.SaveFileDialog.ValidateNames = true;
			if (this.SaveFileDialog.ShowDialog() == DialogResult.OK)
			{
				this.Refresh();
				this.ExecCommand("-U flash:r:\"" + this.SaveFileDialog.FileName + "\":i", 100, false);
			}
		}

		// Token: 0x0600001A RID: 26 RVA: 0x00004E24 File Offset: 0x00003E24
		private void WriteFlashButton_Click(object sender, EventArgs e)
		{
			if (this.FlashFileTextBox.Text.Length == 0)
			{
				MessageBox.Show("Select Flash file", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.FlashFileButton.Focus();
			}
			else if (!File.Exists(this.FlashFileTextBox.Text))
			{
				MessageBox.Show("File not found", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.FlashFileButton.Focus();
			}
			else
			{
				this.ExecCommand("-D -U flash:w:\"" + this.FlashFileTextBox.Text + "\":a", 150, false);
			}
		}

		// Token: 0x0600001B RID: 27 RVA: 0x00004ED0 File Offset: 0x00003ED0
		private void VerifyFlashButton_Click(object sender, EventArgs e)
		{
			if (this.FlashFileTextBox.Text.Length == 0)
			{
				MessageBox.Show("Select Flash file", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.FlashFileButton.Focus();
			}
			else if (!File.Exists(this.FlashFileTextBox.Text))
			{
				MessageBox.Show("File not found", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.FlashFileButton.Focus();
			}
			else
			{
				this.ExecCommand("-U flash:v:\"" + this.FlashFileTextBox.Text + "\":a", 100, false);
			}
		}

		// Token: 0x0600001C RID: 28 RVA: 0x00004F78 File Offset: 0x00003F78
		private void ProgramFlashButton_Click(object sender, EventArgs e)
		{
			if (this.FlashFileTextBox.Text.Length == 0)
			{
				MessageBox.Show("Select Flash file", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.FlashFileButton.Focus();
			}
			else if (!File.Exists(this.FlashFileTextBox.Text))
			{
				MessageBox.Show("File not found", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.FlashFileButton.Focus();
			}
			else
			{
				this.ExecCommand("-e -U flash:w:\"" + this.FlashFileTextBox.Text + "\":a", 150, false);
			}
		}

		// Token: 0x0600001D RID: 29 RVA: 0x00005024 File Offset: 0x00004024
		private void EEPROMFileButton_Click(object sender, EventArgs e)
		{
			this.OpenFileDialog.CheckFileExists = false;
			this.OpenFileDialog.AddExtension = true;
			this.OpenFileDialog.DefaultExt = "eep";
			this.OpenFileDialog.Filter = "EEPROM File(*.eep)|*.eep|All File(*.*)|*.*";
			this.OpenFileDialog.FileName = "";
			this.OpenFileDialog.ShowDialog();
			if (this.OpenFileDialog.FileName.Length > 0)
			{
				this.EEPROMFileTextBox.Text = this.OpenFileDialog.FileName;
			}
		}

		// Token: 0x0600001E RID: 30 RVA: 0x000050C0 File Offset: 0x000040C0
		private void ReadEEPROMButton_Click(object sender, EventArgs e)
		{
			this.SaveFileDialog.AddExtension = true;
			this.SaveFileDialog.DefaultExt = "eep";
			this.SaveFileDialog.FileName = "";
			this.SaveFileDialog.Filter = "EEPROM File (*.eep)|*.eep|All File (*.*)|*.*";
			this.SaveFileDialog.OverwritePrompt = true;
			this.SaveFileDialog.Title = "Save EEPROM data";
			this.SaveFileDialog.ValidateNames = true;
			if (this.SaveFileDialog.ShowDialog() == DialogResult.OK)
			{
				this.Refresh();
				this.ExecCommand("-U eeprom:r:\"" + this.SaveFileDialog.FileName + "\":i", 100, false);
			}
		}

		// Token: 0x0600001F RID: 31 RVA: 0x0000517C File Offset: 0x0000417C
		private void WriteEEPROMButton_Click(object sender, EventArgs e)
		{
			if (this.EEPROMFileTextBox.Text.Length == 0)
			{
				MessageBox.Show("Select EEPROM file", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.EEPROMFileButton.Focus();
			}
			else if (!File.Exists(this.EEPROMFileTextBox.Text))
			{
				MessageBox.Show("File not found", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.EEPROMFileButton.Focus();
			}
			else
			{
				this.ExecCommand("-U eeprom:w:\"" + this.EEPROMFileTextBox.Text + "\":a", 150, false);
			}
		}

		// Token: 0x06000020 RID: 32 RVA: 0x00005225 File Offset: 0x00004225
		private void ExitButton_Click(object sender, EventArgs e)
		{
			Application.Exit();
		}

		// Token: 0x06000021 RID: 33 RVA: 0x00005230 File Offset: 0x00004230
		public MainForm()
		{
			this.InitializeComponent();
			string[] portNames = SerialPort.GetPortNames();
			this.PortComboBox.Items.Add("");
			this.PortComboBox.Items.Add("avrdoper");
			foreach (string text in portNames)
			{
				if (text.Length > 0)
				{
					this.PortComboBox.Items.Add(text);
				}
			}
			this.PortComboBox.Items.Add("LPT1");
			this.PortComboBox.Items.Add("LPT2");
			this.PortComboBox.Items.Add("USB");
			this.PortComboBox.Items.Add("usb");
			this.PortComboBox.Sorted = true;
			this.AvrdudeTextBox.Text = avrdudeGUI.Default.Avrdude;
			if (this.AvrdudeTextBox.Text.Length == 0)
			{
				if (File.Exists("avrdude.exe"))
				{
					this.AvrdudeTextBox.Text = "avrdude.exe";
				}
			}
			if (this.AvrdudeTextBox.Text.Length > 0)
			{
				this.AvrdudeInfo();
			}
			this.WindowCheckBox.Checked = avrdudeGUI.Default.DisplayWindow;
			this.CommandLineOptionTextBox.Text = avrdudeGUI.Default.CommandLineOption;
			this.Text += Application.ProductVersion;
			this.Text = this.Text.Substring(0, this.Text.LastIndexOf('.'));
			this.Text += "]";
		}

		// Token: 0x06000022 RID: 34 RVA: 0x00005428 File Offset: 0x00004428
		private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
		{
			avrdudeGUI.Default.Avrdude = this.AvrdudeTextBox.Text;
			if (this.ProgrammerComboBox.SelectedIndex >= 0)
			{
				avrdudeGUI.Default.Programmer = this.ProgrammerComboBox.SelectedItem.ToString();
			}
			if (this.PortComboBox.SelectedIndex >= 0)
			{
				avrdudeGUI.Default.Port = this.PortComboBox.SelectedItem.ToString();
			}
			if (this.DeviceComboBox.SelectedIndex >= 0)
			{
				avrdudeGUI.Default.Device = this.DeviceComboBox.SelectedItem.ToString();
			}
			avrdudeGUI.Default.DisplayWindow = this.WindowCheckBox.Checked;
			avrdudeGUI.Default.CommandLineOption = this.CommandLineOptionTextBox.Text;
			avrdudeGUI.Default.Save();
		}

		// Token: 0x06000023 RID: 35 RVA: 0x00005510 File Offset: 0x00004510
		private void AvrdudeInfo()
		{
			Process process = this.avrdude("-c ?");
			if (process != null)
			{
				this.ProgrammerComboBox.Items.Clear();
				while (!process.StandardError.EndOfStream)
				{
					string text = process.StandardError.ReadLine();
					text = text.Replace('(', '<');
					text = text.Replace(')', '>');
					Regex regex = new Regex("(\\w+) += ([^\\[]+)");
					Match match = regex.Match(text);
					if (match.Success)
					{
						this.ProgrammerComboBox.Items.Add(string.Concat(new object[]
						{
							match.Groups[2].Value.Trim(),
							" (",
							match.Groups[1],
							")"
						}));
					}
				}
				process.WaitForExit();
				if (this.ProgrammerComboBox.Items.Count > 0)
				{
					this.ProgrammerComboBox.Items.Add("AVR-Doper (stk500v2)");
					this.ProgrammerComboBox.Sorted = true;
				}
				for (int i = 0; i < this.ProgrammerComboBox.Items.Count; i++)
				{
					if (this.ProgrammerComboBox.Items[i].ToString().Equals(avrdudeGUI.Default.Programmer))
					{
						this.ProgrammerComboBox.SelectedIndex = i;
						break;
					}
				}
				process = this.avrdude("-p ?");
				if (process != null)
				{
					this.DeviceComboBox.Items.Clear();
					while (!process.StandardError.EndOfStream)
					{
						string text = process.StandardError.ReadLine();
						text = text.Replace("TINY", "tiny");
						text = text.Replace("MEGA", "mega");
						Regex regex = new Regex("(\\w+) += (\\w+)");
						Match match = regex.Match(text);
						if (match.Success)
						{
							this.DeviceComboBox.Items.Add(match.Groups[2].Value + " (" + match.Groups[1].Value + ")");
						}
					}
					process.WaitForExit();
					if (this.DeviceComboBox.Items.Count > 0)
					{
						this.DeviceComboBox.Sorted = true;
					}
					for (int i = 0; i < this.DeviceComboBox.Items.Count; i++)
					{
						if (this.DeviceComboBox.Items[i].ToString().Equals(avrdudeGUI.Default.Device))
						{
							this.DeviceComboBox.SelectedIndex = i;
							break;
						}
					}
					for (int i = 0; i < this.PortComboBox.Items.Count; i++)
					{
						if (this.PortComboBox.Items[i].ToString().Equals(avrdudeGUI.Default.Port))
						{
							this.PortComboBox.SelectedIndex = i;
							break;
						}
					}
				}
			}
		}

		// Token: 0x06000024 RID: 36 RVA: 0x00005894 File Offset: 0x00004894
		private string GetArg()
		{
			string str = "";
			Regex regex = new Regex("\\((\\w+)\\)");
			Match match = regex.Match(this.ProgrammerComboBox.SelectedItem.ToString());
			if (match.Success)
			{
				str = match.Groups[1].Value;
			}
			string text = "";
			if (this.PortComboBox.SelectedIndex >= 0)
			{
				text = this.PortComboBox.SelectedItem.ToString();
			}
			string str2 = "";
			match = regex.Match(this.DeviceComboBox.SelectedItem.ToString());
			if (match.Success)
			{
				str2 = match.Groups[1].Value;
			}
			string text2 = " -c " + str;
			if (text.Length > 0)
			{
				text2 = text2 + " -P " + text;
			}
			text2 = text2 + " -p " + str2;
			if (this.CommandLineOptionTextBox.Text.Length > 0)
			{
				text2 = text2 + " " + this.CommandLineOptionTextBox.Text + " ";
			}
			return text2;
		}

		// Token: 0x06000025 RID: 37 RVA: 0x000059E0 File Offset: 0x000049E0
		private Process avrdude(string arg)
		{
			Process result;
			if (this.AvrdudeTextBox.Text.Length == 0)
			{
				result = null;
			}
			else
			{
				Process process;
				try
				{
					process = Process.Start(new ProcessStartInfo
					{
						FileName = this.AvrdudeTextBox.Text,
						RedirectStandardError = true,
						CreateNoWindow = true,
						UseShellExecute = false,
						Arguments = arg
					});
				}
				catch
				{
					process = null;
				}
				result = process;
			}
			return result;
		}

		// Token: 0x06000026 RID: 38 RVA: 0x00005A6C File Offset: 0x00004A6C
		private int ExecCommand(string arg, int maxProgress, bool ignoreError)
		{
			int result;
			if (this.AvrdudeTextBox.Text.Length == 0)
			{
				MessageBox.Show("Select avrdude.exe File", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.AvrdudeButton.Focus();
				result = 0;
			}
			else if (this.ProgrammerComboBox.SelectedIndex < 0)
			{
				MessageBox.Show("Select Programmer", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.ProgrammerComboBox.Focus();
				result = 0;
			}
			else if (this.DeviceComboBox.SelectedIndex < 0)
			{
				MessageBox.Show("Select Device", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.DeviceComboBox.Focus();
				result = 0;
			}
			else
			{
				Cursor value = Cursor.Current;
				try
				{
					Cursor.Current = Cursors.WaitCursor;
					ProcessStartInfo processStartInfo = new ProcessStartInfo();
					processStartInfo.Arguments = "";
					if (this.WindowCheckBox.Checked)
					{
						processStartInfo.FileName = Environment.GetEnvironmentVariable("comspec");
						processStartInfo.Arguments = " /K \"" + this.AvrdudeTextBox.Text + "\" ";
					}
					else
					{
						processStartInfo.FileName = this.AvrdudeTextBox.Text;
					}
					if (!this.WindowCheckBox.Checked)
					{
						ProcessStartInfo processStartInfo2 = processStartInfo;
						processStartInfo2.Arguments = processStartInfo2.Arguments + this.GetArg() + " -u " + arg;
						processStartInfo.CreateNoWindow = true;
						processStartInfo.RedirectStandardError = true;
						processStartInfo.UseShellExecute = false;
					}
					else
					{
						ProcessStartInfo processStartInfo3 = processStartInfo;
						processStartInfo3.Arguments = processStartInfo3.Arguments + this.GetArg() + " " + arg;
					}
					processStartInfo.WorkingDirectory = Environment.GetEnvironmentVariable("temp");
					Process process = Process.Start(processStartInfo);
					StringBuilder stringBuilder = new StringBuilder();
					if (!this.WindowCheckBox.Checked)
					{
						this.ProgressBar.Maximum = maxProgress;
						this.ProgressBar.Value = 0;
						while (!process.StandardError.EndOfStream)
						{
							int num = process.StandardError.Read();
							if (num == 35 && this.ProgressBar.Value < this.ProgressBar.Maximum)
							{
								this.ProgressBar.Value++;
							}
							stringBuilder.Append((char)num);
						}
					}
					process.WaitForExit();
					Cursor.Current = value;
					if (!this.WindowCheckBox.Checked && process.ExitCode != 0 && !ignoreError)
					{
						SystemSounds.Asterisk.Play();
						Form form = new ErrorMessageForm();
						form.Text = this.Text + " Error";
						form.Controls["MessageTextBox"].Text = stringBuilder.ToString();
						form.ShowDialog();
						this.ProgressBar.Value = 0;
						result = 1;
					}
					else
					{
						this.ProgressBar.Value = 0;
						result = 0;
					}
				}
				catch
				{
					Cursor.Current = value;
					this.ProgressBar.Value = 0;
					result = 1;
				}
			}
			return result;
		}
	}
}
